insert overwrite table jms_dm.dm_lmdm_three_segment_monitoring_error_detail_dt partition (dt)
select 
 t.order_id
,t.input_time
,t.waybill_no
,t.order_source_code
,t.order_source_name
,t.real_pick_name
,t.real_pick_code
,t.receiver_province_id
,t.receiver_province_desc
,t.receiver_city_id
,t.receiver_city_desc
,t.receiver_area_id
,t.receiver_area_desc
,t.receiver_detailed_address
,t.dispatch_name
,t.dispatch_code
,t.deliver_agent_name
,t.deliver_agent_code
,t.deliver_name string
,t.deliver_code string
,t.deliver_later_user
,t.deliver_later_user_code
,t.is_abnormal
,t.first_code
,t.second_code
,t.third_code
,t.sign_later_scantime
,t.first_code_fail
,t.first_code_error
,t.second_code_fail
,t.second_code_error
,t.third_code_fail
,t.third_code_error
,t.dt as sign_later_scantime_dt
,t.sign_later_scansitecode
,t.sign_later_scansite
,t.sj_first_code
,t.sj_second_code
,t.sj_third_code
,'{{ execution_date | cst_ds }}' as dt
from jms_dm.dm_lmdm_three_segment_monitoring_detail_dt t
where t.dt = '{{ execution_date | cst_ds }}'
and (t.first_code_fail=1 or first_code_error = 1 or second_code_fail = 1 or second_code_error = 1 or third_code_fail = 1 or third_code_error = 1)

 distribute by pmod(hash(rand()), 17);